import { Application } from 'egg';
import * as pageFindPlugin from 'mongoose-paginate';
import { CheckStandPaymentType } from '../constants/index';

export default (app: Application) => {
  const mongoose = app.mongoose;
  const ObjectId = mongoose.Schema.Types.ObjectId;
  const schema = new mongoose.Schema({
    // 模块名称
    model: {
      type: String,
      requied: true,
      emnu: CheckStandPaymentType,
    },
    // 项目id
    project: ObjectId,
    // 抵扣百分百
    percentage: {
      type: Number,
      requied: true,
      default: 0,
    },
    // 状态
    status: {
      type: Number,
      requied: true,
      default: 0,
    },
  });
  schema.plugin(pageFindPlugin, { limit: 10 });
  schema.index({});
  return mongoose.model('Coinrules', schema, 'coinrules');
};
